package pl.enigmatic.validation;

public abstract class HasValueValidator<T> implements Validator, SimpleValidator<T> {

	private final HasValue<T> object;

	public HasValueValidator(final HasValue<T> object) {
		this.object = object;
	}

	@Override
	public final boolean isValid() {
		return isValueValid(object.getValue());
	}

	public HasValue<T> getObject() {
		return object;
	}

	public static class Impl<T> extends HasValueValidator<T> {

		private final SimpleValidator<T> validator;

		public Impl(final HasValue<T> object, final SimpleValidator<T> validator) {
			super(object);
			this.validator = validator;
		}

		@Override
		public boolean isValueValid(final T val) {
			return validator.isValueValid(val);
		}
	}

}
